package com.member.server.domain.dto;

import com.alibaba.fastjson.JSON;
import com.member.server.entity.Account;
import com.member.server.entity.Member;

import java.io.Serializable;
import java.util.List;

/**
 * @author gaojx1993
 * @version 1.0
 * @description MemAccInfoDTO
 * @since 2023/7/12 11:24
 */
public class MemAccInfoDTO implements Serializable {

    private final Member member;

    private final Long totalBalance;

    private final List<Account> accounts;

    public MemAccInfoDTO(Member member, List<Account> accounts) {
        this.member = member;
        this.accounts = accounts;
        this.totalBalance = accounts.stream().mapToLong(Account::getBalance).sum();
    }

    public Member getMember() {
        return member;
    }

    public Long getTotalBalance() {
        return totalBalance;
    }

    public List<Account> getAccounts() {
        return accounts;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
